package com.skp.shaphan.ui.results;

import java.awt.Component;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellRenderer;

import com.skp.shaphan.sql.ValueToText;

/**
 * A cell field to display the value of a field in the results
 * @author Stephen Phillips
 *
 */
public class ResultsCell extends JTextField implements TableCellRenderer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ResultsCell() {
		super("**");
	}
	public ResultsCell(ResultSet results, int fieldIndex) throws SQLException, IOException {
		Object value = results.getObject(fieldIndex);
		this.setText(ValueToText.getInstance().convert(value));
		this.setColumns(this.getText().length());
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		return (ResultsCell)value;
	}
}
